package com.hust.bridgecheck.serviceImpl.Settings;

import com.hust.bridgecheck.entity.DailySensorData;
import com.hust.bridgecheck.entity.Notify;
import com.hust.bridgecheck.repository.DailySDataRepository;
import com.hust.bridgecheck.repository.NotifyRepository;
import com.hust.bridgecheck.service.Settings.NotifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NotifyServiceImpl implements NotifyService {

    @Autowired
    NotifyRepository notifyRepository;

    @Autowired
    DailySDataRepository dailySDataRepository;

    @Override
    public Notify addNotify(Notify notify) {
        return notifyRepository.save(notify);
    }

    @Override
    public DailySensorData addSensorData(DailySensorData dailySensorData) {
        return dailySDataRepository.save(dailySensorData);
    }

    @Override
    public void deleteNotify(Integer notifyID) {
        notifyRepository.deleteById(notifyID);
    }

    @Override
    public Notify updateNotify(Notify notify) {
        return notifyRepository.save(notify);
    }

    @Override
    public Notify getNotify(Integer notifyID) {
        return notifyRepository.findById(notifyID).get();
    }

    @Override
    public List<Notify> getAllNotify() {
        return notifyRepository.findAll();
    }

    @Override
    public List<Notify> getUserNotify(Integer uid, Integer readed) {
        return notifyRepository.getAllUnreadNotify(uid,readed);
    }

    @Override
    public int UpdateReaded(Integer NID) {
        return notifyRepository.UpdateReaded(NID);
    }

    @Override
    public List<DailySensorData> getAllReport(Integer Flag, String Startime, String Endtime) {
        return dailySDataRepository.getDailyReportByFlag(Flag,Startime,Endtime);
    }


}
